package cn.lyq.card.ui.result

import android.content.Context
import android.content.Intent
import cn.lyq.card.R
import cn.lyq.card.base.BaseActivity
import cn.lyq.card.ui.realname.RealNameAuthActivity
import cn.lyq.card.utils.setClick
import kotlinx.android.synthetic.main.act_result.*
import java.text.SimpleDateFormat
import java.util.*

class ResultActivity : BaseActivity() {

    companion object {

        private const val KEY_TYPE = "TYPE"

        /**
         * @param type 0修改基础信息，1实名认证提交成功，2实名认证成功，3实名认证失败，
         * 4提现申请已提交，5意见提交成功
         */
        @JvmStatic
        fun start(context: Context, type: Int) {
            val starter = Intent(context, ResultActivity::class.java)
                .putExtra(KEY_TYPE, type)
            context.startActivity(starter)
        }
    }

    private val type by lazy {
        intent.getIntExtra(KEY_TYPE, 0)
    }

    override fun getLayoutId(): Int = R.layout.act_result

    private val imgRes = arrayOf(
        R.drawable.ic_check_circle, R.drawable.ic_check_circle,
        R.drawable.ic_auth_success, R.drawable.ic_auth_failed,
        R.drawable.ic_success, R.drawable.ic_check_circle
    )

    private val title = arrayOf(
        "修改成功", "资料提交成功",
        "认证成功", "认证失败",
        "提现申请已提交", "意见提交成功"
    )

    private val subTitle = arrayOf(
        "修改成功", "资料已提交成功",
        "认证成功！", "认证失败！",
        "提现申请已提交，等待人工审核", "意见提交成功"
    )

    private val tip = arrayOf(
        "",
        "平台将在3-7个工作日内完成审核，\n请耐心等待~",
        "恭喜您！您已完成实名认证，\n功能已全部解锁，赶紧去体验吧~",
        "失败原因：真实姓名与银行卡不符，\n请重新提交资料认证审核！",
        "",
        "感谢您的意见，我们将不断完善\n带给您更好的体验！"
    )

    private val action = arrayOf(
        "返回", "返回",
        "返回", "重新认证",
        "完成", "返回"
    )

    override fun initView() {
        super.initView()
        setMyTitle(title[type])
        img.setImageResource(imgRes[type])
        tvSubTitle.text = subTitle[type]
        tvTip.text = tip[type]
        tvAction.text = action[type]
        if (type == 4) {
            //提现成功，tip显示时间
            tvTip.text = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA).format(Date())
        }
    }

    override fun initListener() {
        super.initListener()
        tvAction.setClick {
            if (type == 3) {
                //认证失败，重新认证
                startActivity(RealNameAuthActivity::class.java)
                finish()
            } else {
                onBackPressed()
            }
        }
    }
}